.PHONY: init
init:
	go get google.golang.org/protobuf/cmd/protoc-gen-go
	go get google.golang.org/grpc/cmd/protoc-gen-go-grpc
	# 这是新版本 的 gorm  目前先不用
	#go get gorm.io/gorm
	go get github.com/jinzhu/gorm
	go get google.golang.org/grpc/reflection
	go get go.uber.org/zap
	go get github.com/ahmetb/go-linq/v3
	go get github.com/spf13/viper
	go get github.com/gin-gonic/gin
	go get github.com/fatih/color
	go get gorm.io/driver/postgres
	go get github.com/casbin/casbin/v2
	go get github.com/casbin/gorm-adapter/v3
	# grpc 生成后支持 gorm 数据结构
	go get github.com/infobloxopen/protoc-gen-gorm
	go get github.com/infobloxopen/atlas-app-toolkit/gorm


.PHONY: protoc
protoc:
	for file in $$(git ls-files '*.proto'); do \
		protoc \
		-I $$(dirname $$file)  \
		-I ./third_party \
		-I ./protobuf \
		--go_out=:$$(dirname $$file) --go_opt=paths=source_relative \
		--go-grpc_out=:$$(dirname $$file) --go-grpc_opt=paths=source_relative \
		--gorm_out=engine=postgres:$$(dirname $$file) --gorm_opt=paths=source_relative \
		$$file; \
	done

#.PHONY: dtm-server
#dtm-server:  # 注意使用 dtm的时候 要 克隆 源码 运行 才行
#	@echo "Start DTM server, Please see: https://github.com/dtm-labs/dtm"
#	@echo "From Source: git clone https://github.com/dtm-labs/dtm && cd dtm && go run main.go"
#	@echo "For Mac: brew install dtm"

.PHONY: docker-build
docker-build:
	docker build -t blog/permission-server:latest -f ./build/docker/permission/Dockerfile .
	docker build -t blog/dict-server:latest -f ./build/docker/dict/Dockerfile .
	docker build -t blog/blog-server:latest -f ./build/docker/blog/Dockerfile .
	docker build -t blog/post-server:latest -f ./build/docker/post/Dockerfile .
	docker build -t blog/comment-server:latest -f ./build/docker/comment/Dockerfile .
.PHONY: docker-test
docker-test:
	docker build -t http-test:latest -f ./build/docker/test/Dockerfile .

.PHONY: kube-deploy
kube-deploy:
	kubectl apply -f ./deployments/
	kubectl apply -f ./deployments/dtm/
	kubectl apply -f ./deployments/permission/
	kubectl apply -f ./deployments/istio/
	kubectl apply -f ./deployments/dict/
	kubectl apply -f ./deployments/blog/
	kubectl apply -f ./deployments/comment/
	kubectl apply -f ./deployments/post/
	kubectl apply -f ./deployments/addons/

.PHONY: kube-delete
kube-delete:
	kubectl delete -f ./deployments/
	kubectl delete -f ./deployments/dtm/
	kubectl delete -f ./deployments/permission/
	kubectl delete -f ./deployments/istio/
	kubectl delete -f ./deployments/dict/
	kubectl delete -f ./deployments/blog/
	kubectl delete -f ./deployments/comment/
	kubectl delete -f ./deployments/post/
	kubectl delete -f ./deployments/addons/
